package com.bng8.superstar_cms.util;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * ClassName: CommonMetaObjectHandler
 * Package: com.bng8.superstar_cms.util
 * Date: 2023/8/15 10:05
 * Author: 安知（13921877634）
 */
@Component
@Slf4j
public class CommonMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {

        this.strictInsertFill(metaObject, "gmtCreate",
                LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "gmtUpdate",
                LocalDateTime.class, LocalDateTime.now());

        this.strictInsertFill(metaObject, "creator",
                String.class, "administrator");
        this.strictInsertFill(metaObject, "operator",
                String.class, "administrator");

        this.strictInsertFill(metaObject, "deleted",
                Integer.class, 1);
        this.strictInsertFill(metaObject, "version",
                Long.class, 1L);
    }

    @Override
    public void updateFill(MetaObject metaObject) {

        this.strictUpdateFill(metaObject, "gmtUpdate",
                LocalDateTime.class, LocalDateTime.now());

        this.strictUpdateFill(metaObject, "operator",
                String.class, "administrator");
    }
}
